<#include "/ftl/lib/operations.ftl"/>
<div class="easyui-layout" fit="true">
	<div data-options="region:'west',split:true" style="width: 200px;" title="${action.getDatagridTitle('classify')}" >
		<ul class="easyui-tree" data-options="url:'${request.contextPath}${namespace?default('')}/mp/product/classify-datagrid.json',animate:true,
			onClick:function(node){
				if(node.id==''){
					cid_${action_id} = 0;
				}else{
					cid_${action_id} = parseInt(node.id);
				}
				$('#datagrid_${action_id}').datagrid('options').queryParams={'_searcher_eq_classifyId?long':node.id};
				$('#datagrid_${action_id}').datagrid('reload');
			}"></ul>
	</div>
	<div data-options="region:'center',split:true" >
		<div class="easyui-layout" fit="true" border="false">
			<div region="north"  style="padding:5px;border:1px solid #ddd; background-color: #f4f4f4" id="global_${action_id}"  >
			</div> 
			<div data-options="region:'center',split:true,border:false" title="商品" style="height: 100px;" >
				<div class="easyui-panel" data-options="href:'${request.contextPath}${namespace?default('')}/mp/product/product-list.htm?action_id=${action_id}',fit:true">
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var cid_${action_id} = 0;
function add_${action_id}(){
	if(!cid_${action_id}){
		$.messager.alert("",'${action.getText('product.action.no.classify.warning')}','warning');
		return;
	}
	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/product/product-form.htm?action_id=${action_id}&classifyId='+cid_${action_id},
		width : 700,
		height : 600,
		modal : true,
		resizable:true,
		title : '${action.getText('bg.datagrid.add')}',
		buttons : [ {
			text : '${action.getText('bg.datagrid.add')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#form_${action_id}').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/product/product-add.json',
					onSubmit: function(){
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						if(json.level!='error'){
							d.dialog('destroy');
							$("#datagrid_${action_id}").datagrid('reload');
						}
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		}
	});	
}

function edit_${action_id}(data){
	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/product/product-edit.htm?ajax=false&action_id=${action_id}&id='+data.id+'&classifyId='+data.classifyId,
		width : 700,
		height : 600,
		modal : true,
		resizable:true,
		title : '${action.getText('bg.datagrid.edit')}',
		buttons : [ {
			text : '${action.getText('bg.datagrid.edit')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#form_${action_id}').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/product/product-update.json',
					onSubmit: function(){
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						if(json.level!='error'){
							d.dialog('destroy');
							$("#datagrid_${action_id}").datagrid('reload');
						}
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		}
	});
}

function delete_${action_id}(data) {
	$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('bg.datagrid.delete.ask')}', function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/mp/product/product-delete.json',
				data : {
					deletes : data.id
				},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					if(json.level!='error'){
						$("#datagrid_${action_id}").datagrid('reload');
					}
				}
			});
		}
	});
}

function stock_${action_id}(data){
	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/product/product-stock.htm?action_id=${action_id}&id='+data.id,
		width : 600,
		height : 500,
		modal : true,
		resizable:true,
		title : '${action.getText('bg.datagrid.edit')}',
		buttons : [ {
			text : '${action.getText('bg.datagrid.edit')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#stock_${action_id}').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/product/product-editStock.json',
					onSubmit: function(){
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						if(json.level!='error'){
							d.dialog('destroy');
							$("#datagrid_${action_id}").datagrid('reload');
						}
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		}
	});
}

function yes_marketEnable_${action_id}(data){//上架
	if(data.marketEnable==2){
		marketEnable_${action_id}(data,1,"上架将马上在网站上显示，是否确认");
	}
}

function no_marketEnable_${action_id}(data){//下架
	if(data.marketEnable==1){
		marketEnable_${action_id}(data,2,"下架后商品在网站上消失，是否确认");
	}
}

function marketEnable_${action_id}(data,state,msg){
	$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', msg, function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/mp/product/product-marketEnable.json',
				data : {
					id : data.id,
					state : state
				},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					if(json.level!='error'){
						$("#datagrid_${action_id}").datagrid('reload');
					}
				}
			});
		}
	});
}
</script>
<@operations contextUri='mp/product/product' />